package com.example.tongue.ui.Online.Body;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.example.tongue.ui.Online.Body.utils.ScoreCalculationSeven;
import com.example.tongue.R;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class HeatAndHumidity extends Activity implements View.OnClickListener {
    //定义控件
    private Button next5, whetherHeatAndHumidity;
    private RadioGroup greasyNose, acne,
            bitterMouth, stickyStool,
            urethralFever, yellowLeucorrhea,
            wetScrotum;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.heatandhumidity);
        //控件绑定资源
        next5 = findViewById(R.id.Next5);

                greasyNose = findViewById(R.id.GreasyNose);
                acne = findViewById(R.id.Acne);
                bitterMouth = findViewById(R.id.BitterMouth);
                stickyStool = findViewById(R.id.StickyStool);
                urethralFever = findViewById(R.id.UrethralFever);
                yellowLeucorrhea = findViewById(R.id.YellowLeucorrhea);
                wetScrotum = findViewById(R.id.WetScrotum);

        //注册监听器  
        next5.setOnClickListener(this);

                greasyNose.setOnClickListener(this);
                acne.setOnClickListener(this);
                bitterMouth.setOnClickListener(this);
                stickyStool.setOnClickListener(this);
                urethralFever.setOnClickListener(this);
                yellowLeucorrhea.setOnClickListener(this);
                wetScrotum.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.Next5: {
                //计算结果,把结果写入缓存
                HeatAndHumidityResult();
//                Toast.makeText(HeatAndHumidity.this, "进入血瘀质", Toast.LENGTH_SHORT).show();
                startActivity(new Intent(HeatAndHumidity.this, BloodStasis.class));
            }
            break;


        }


    }
    public void HeatAndHumidityResult(){
        int   greasyNoseid=  greasyNose.getCheckedRadioButtonId();
        RadioButton  greasyNosebtn= findViewById( greasyNoseid);
        String  greasyNosefin= greasyNosebtn.getText().toString();

        int    acneid=   acne.getCheckedRadioButtonId();
        RadioButton acnebtn= findViewById(acneid);
        String acnefin=acnebtn.getText().toString();

        int  bitterMouthid=   bitterMouth.getCheckedRadioButtonId();
        RadioButton  bitterMouthbtn= findViewById(bitterMouthid);
        String  bitterMouthfin=   bitterMouthbtn.getText().toString();

        int  stickyStoolid=  stickyStool.getCheckedRadioButtonId();
        RadioButton  stickyStoolbtn= findViewById( stickyStoolid);
        String stickyStoolfin= stickyStoolbtn.getText().toString();

        int  urethralFeverid= urethralFever.getCheckedRadioButtonId();
        RadioButton  urethralFeverbtn= findViewById( urethralFeverid);
        String  urethralFeverfin= urethralFeverbtn.getText().toString();


        int   yellowLeucorrheaid=   yellowLeucorrhea.getCheckedRadioButtonId();
        RadioButton    yellowLeucorrheabtn= findViewById( yellowLeucorrheaid);
        String     yellowLeucorrheafin=    yellowLeucorrheabtn.getText().toString();

        int wetScrotumid=wetScrotum.getCheckedRadioButtonId();
        RadioButton wetScrotumbtn= findViewById(wetScrotumid);
        String wetScrotumfin=wetScrotumbtn.getText().toString();





        Map<String,Integer>   greasyNoseMap=new HashMap<String,Integer>();
        greasyNoseMap.put("没有",1);
        greasyNoseMap.put("很少",2);
        greasyNoseMap.put("有时",3);
        greasyNoseMap.put("常常",4);
        greasyNoseMap.put("经常",5);

        Map<String,Integer>  acneMap=new HashMap<String,Integer>();
        acneMap.put("没有",1);
        acneMap.put("很少",2);
        acneMap.put("有时",3);
        acneMap.put("常常",4);
        acneMap.put("经常",5);

        Map<String,Integer>   bitterMouthMap=new HashMap<String,Integer>();
        bitterMouthMap.put("没有",1);
        bitterMouthMap.put("很少",2);
        bitterMouthMap.put("有时",3);
        bitterMouthMap.put("常常",4);
        bitterMouthMap.put("经常",5);

        Map<String,Integer> stickyStoolMap=new HashMap<String,Integer>();
        stickyStoolMap.put("没有",1);
        stickyStoolMap.put("很少",2);
        stickyStoolMap.put("有时",3);
        stickyStoolMap.put("常常",4);
        stickyStoolMap.put("经常",5);

        Map<String,Integer> yellowLeucorrheaMap=new HashMap<String,Integer>();
        yellowLeucorrheaMap.put("没有",1);
        yellowLeucorrheaMap.put("很少",2);
        yellowLeucorrheaMap.put("有时",3);
        yellowLeucorrheaMap.put("常常",4);
        yellowLeucorrheaMap.put("经常",5);

        Map<String,Integer>  urethralFeverMap=new HashMap<String,Integer>();
        urethralFeverMap.put("没有",1);
        urethralFeverMap.put("很少",2);
        urethralFeverMap.put("有时",3);
        urethralFeverMap.put("常常",4);
        urethralFeverMap.put("经常",5);

        Map<String,Integer> wetScrotumMap=new HashMap<String,Integer>();
        wetScrotumMap.put("没有",1);
        wetScrotumMap.put("很少",2);
        wetScrotumMap.put("有时",3);
        wetScrotumMap.put("常常",4);
        wetScrotumMap.put("经常",5);







        Integer heatAndHumidityresult = greasyNoseMap.get( greasyNosefin)+
                acneMap.get(   acnefin) +
                bitterMouthMap.get(  bitterMouthfin) +
                stickyStoolMap.get( stickyStoolfin)+
                yellowLeucorrheaMap.get( yellowLeucorrheafin)+
                urethralFeverMap.get(  urethralFeverfin)+
                wetScrotumMap.get( wetScrotumfin)
                ;
        ScoreCalculationSeven scoreCalculationSeven=new ScoreCalculationSeven(heatAndHumidityresult);
        String ConversionScore=scoreCalculationSeven.getResult();
        TextView heatAndHumidityResult=(TextView)findViewById(R.id.HeatAndHumidityResult);
        heatAndHumidityResult.setText("湿热质结果:"+ConversionScore);

        File dataFileDir=new File(getExternalCacheDir(),"PhysiqueDataFile");
        FileWriter writer=null;
        try {
            //开启写入流
            writer=new FileWriter(dataFileDir+"/PhysiqueData.txt",true);
            writer.write(ConversionScore+"\n");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                System.out.println("数据文件已生成");
            }
        }
    }
}


